package com.onlinelearn.chatservice.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RealTimeChatService {
    @Autowired
    private WebSocketService webSocketService;

    @Autowired
    private ChatRepository chatRepository;

    public void handleIncomingMessage(ChatMessage message) {
        // 敏感词过滤
        String filteredContent = sensitiveWordFilter.filter(message.getContent());
        message.setContent(filteredContent);

        // 保存消息
        chatRepository.save(message);

        // 实时推送
        webSocketService.sendMessageToCourse(
            message.getCourseId(), 
            message
        );
    }
} 